package cn.gzsxt.music.mapper;


import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.gzsxt.music.query.AdminQueryObject;

@Mapper
public interface AdminMapper {
	
	@Insert("INSERT INTO tb_admin ( admin_name, admin_pass, create_date, role_id) VALUES (#{admin_name}, #{admin_pass}, #{create_date}, #{role_id})")
	//@Options(useGeneratedKeys=true,keyProperty="admin_id",keyColumn="admin_id")
	public int insert(Map<String, Object> map);
	
	
	/**
	 * 根据条件查询结果
	 * 
	 * @param qo 条件对象
	 * @return 结果集
	 */
	@Select("select a.*,r.role_name from tb_admin a,tb_role r where a.role_id = r.role_id limit #{beginIndex},#{rows}")
	List<Map<String, Object>> selectAdminListByCondition(AdminQueryObject qo);

	/**
	 * 根据条件查询总数
	 * 
	 * @param qo 条件对象
	 * @return 总数
	 */
	@Select("select count(*) from tb_admin a,tb_role r where a.role_id = r.role_id")
	Long selectAdminTotalByCondition(AdminQueryObject qo);

	/**
	 *  登录功能
	 * @param params
	 * @return
	 */
	@Select("select * from tb_admin where admin_name = #{admin_name} and admin_pass = #{admin_pass}")
	public Map<String, Object> selectNameAndPass(Map<String, Object> params);

	/**
	 * 	修改用户
	 * @param params
	 * @return
	 */
	@Update("update tb_admin set admin_name = #{admin_name} ,admin_pass = #{admin_pass},role_id = #{role_id},admin_status = #{admin_status} where admin_id = #{admin_id}")
	public int updateAdmin(Map<String, Object> params);

	
}
